package com.easyjop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.easyjop.entity.enums.PageSize;
import com.easyjop.entity.query.QuestionBankQuery;
import com.easyjop.entity.po.QuestionBank;
import com.easyjop.entity.vo.PaginationResultVO;
import com.easyjop.entity.query.SimplePage;
import com.easyjop.mappers.QuestionBankMapper;
import com.easyjop.service.QuestionBankService;
import com.easyjop.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("questionBankService")
public class QuestionBankServiceImpl implements QuestionBankService {

	@Resource
	private QuestionBankMapper<QuestionBank, QuestionBankQuery> questionBankMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<QuestionBank> findListByParam(QuestionBankQuery param) {
		return this.questionBankMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(QuestionBankQuery param) {
		return this.questionBankMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<QuestionBank> findListByPage(QuestionBankQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<QuestionBank> list = this.findListByParam(param);
		PaginationResultVO<QuestionBank> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(QuestionBank bean) {
		return this.questionBankMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<QuestionBank> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.questionBankMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<QuestionBank> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.questionBankMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(QuestionBank bean, QuestionBankQuery param) {
		StringTools.checkParam(param);
		return this.questionBankMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(QuestionBankQuery param) {
		StringTools.checkParam(param);
		return this.questionBankMapper.deleteByParam(param);
	}

	/**
	 * 根据BankId获取对象
	 */
	@Override
	public QuestionBank getQuestionBankByBankId(Integer bankId) {
		return this.questionBankMapper.selectByBankId(bankId);
	}

	/**
	 * 根据BankId修改
	 */
	@Override
	public Integer updateQuestionBankByBankId(QuestionBank bean, Integer bankId) {
		return this.questionBankMapper.updateByBankId(bean, bankId);
	}

	/**
	 * 根据BankId删除
	 */
	@Override
	public Integer deleteQuestionBankByBankId(Integer bankId) {
		return this.questionBankMapper.deleteByBankId(bankId);
	}

    @Override
    public List<QuestionBank> loadAllCategoryByType(Integer type) {
		QuestionBankQuery questionBankQuery = new QuestionBankQuery();
		questionBankQuery.setType(type);
		questionBankQuery.setOrderBy("sort asc");
		return this.findListByParam(questionBankQuery);
    }
}